﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;



///<summmary>
///
///</summmary>
public class AudioManager : MonoBehaviour
{

    static AudioManager current;

    [Header("游戏声音")]
    public AudioClip ambientClip;
    public AudioClip musicClip;

    [Header("主角音效")]
    public AudioClip[] walkFXClip;
    public AudioClip attackFXClip;
    public AudioClip jumpFXClip;
    public AudioClip startLevelClip;
    public AudioClip deathClip;
    public AudioClip ccClip;

    [Header("商店音效")]
    public AudioClip buyVoice;
    public AudioClip sqVoice;

    [Header("道具音效")]
    public AudioClip StVoice;
    public AudioClip ZzVoice;
    public AudioClip LdzVoice;
    public AudioClip AycrVoice;
    public AudioClip DsjlVoice;
    public AudioClip LhsVoice;

    public AudioClip BowVoice;
    public AudioClip FeibiaoVoice;
    public AudioClip DunVoice;

    [Header("敌人音效")]
    public AudioClip BossVoice;
    public AudioClip SsVoice;
    public AudioClip enemyDeadVoice;

    AudioSource playerSource;
    AudioSource gkSource;
    AudioSource sdSource;
    AudioSource skillSource;
    AudioSource enemySource;

    public AudioMixerGroup ambientGroup, musicGroup, FXGroup, playerGroup, voiceGroup;
    // Start is called before the first frame update
    void Awake()
    {
        current = this;

        //DontDestroyOnLoad(gameObject);

        playerSource = gameObject.AddComponent<AudioSource>();
        gkSource = gameObject.AddComponent<AudioSource>();
        sdSource = gameObject.AddComponent<AudioSource>();
        skillSource = gameObject.AddComponent<AudioSource>();
        enemySource = gameObject.AddComponent<AudioSource>();

        StartLevelAudio();
    }

    void StartLevelAudio()
    {
        current.gkSource.clip = current.musicClip;
        current.gkSource.loop = true;
        current.gkSource.Play();
    }

    public static void PlayerAttackAudio()
    {
        current.playerSource.clip = current.attackFXClip;
        current.playerSource.loop = false;
        current.playerSource.Play();
    }

    public static void PlayFootstepAudio()
    {
        int index = Random.Range(0,current.walkFXClip.Length);

        current.playerSource.clip = current.walkFXClip[index];
        current.playerSource.Play();
    }

    public static void PlayerJumpAudio()
    {
        current.playerSource.clip = current.jumpFXClip;
        current.playerSource.Play();
    }

    public static void PlayerCCAudio()
    {
        current.playerSource.clip = current.ccClip;
        current.playerSource.loop = false;
        current.playerSource.Play();
    }
}




